from neo4j_db.nodeType import (
    HERO_NODE_TYPE,
    HERO_LOCATION_NODE_TYPE,
    HERO_ROLE_NODE_TYPE
)
from neo4j_db.operation import (
    matchNode,
    getRelationshipByTwoNode,
    matchNodeByKeyword
)
from utils.wrapData import (
    wrapNodeAndRelationResult
)

# 获取所有的英雄结点
def getAllHeroNode(limit = None):
    nodes = matchNode(nodeType = HERO_NODE_TYPE, limit = limit)
    return nodes
    
# 根据英雄的名称匹配英雄的节点，同时返回相关的边
def matchHeroRelatedMessageByName(heroName):
    # 1.匹配结点
    nodes = matchNode(nodeType = HERO_NODE_TYPE, name = heroName)
    # 1.1 如果找不到这个结点,直接返回None
    if len(nodes) == 0:
        return wrapNodeAndRelationResult(node = None, relationships = None)
    # 1.2 如果找到了这个结点,就去查找这个结点的边,然后返回
    node = nodes[0]
    relationships = getRelationshipByTwoNode(node)
    result = wrapNodeAndRelationResult(node = node, relationships = relationships)
    return result

# 根据关键词搜索相应的节点以及边的内容
def searchHeroNodeByKeywords(keyword):
    # 1.匹配需要的节点
    nodes = matchNodeByKeyword(HERO_NODE_TYPE, keyword)
    # 1.1 如果返回的为空,则直接返回None
    if len(nodes) == 0:
        return None
    # 1.2 有匹配的数据则直接返回
    return nodes
